/*
 * @Author: ydli
 * @LastEditTime: 2021-04-26 21:53:57
 * @Description: 
 */
import axios from 'axios';
import store from '../store';

// baseURL:"http://api/vikingship.xyz",
const http = axios.create({
    baseURL: "/api",
    timeout: 3000
})

// 请求拦截器
http.interceptors.request.use(config => {
    console.log("拦截请求!!!!!");
    store.commit('setError', { status: false, message: '' });
    store.commit('setLoading', true);
    return config
}, (e) => {
    return e;
});

// 响应拦截器
http.interceptors.response.use(response => {
    console.log("响应拦截!!!!");
    store.commit('setLoading', false);
    return response;
}, (e) => {
    // 全局错误处理
    const { error } = e.response.data;
    store.commit('setError', { status: true, message: error });
    store.commit('setLoading', false);
    return Promise.reject(error);
});

export default http;


// `data` 是作为请求主体被发送的数据

// function apiAxios(method,url,params,success,failure){
//     http({
//         method:method,
//         url:url,
//         data:method === 'POST' || method === 'PUT' ? params : null,
//         params:method === 'GET' || method === 'DELETE' ? params : null,
//         headers:{
//             'access_token':'xxxxxx'
//         }
//     })
// }

